All Questions
14 questions
3votes
2answers
1kviews
Sorted insert on a doubly linked list (HackerRank)
I've decided to do a simple linked list question to brush up my Java & CS. This is the solution for Given a reference to the head of a doubly-linked list and an integer, \$data\$ , create a ...
3votes
1answer
281views
Convert a Binary Tree to Doubly Linked List
Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
5votes
2answers
503views
Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)
Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
2votes
2answers
2kviews
Swap Nodes in Pairs in singly linked list
Description: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only ...
1vote
3answers
806views
Remove nth node from last position in linked list
Description: Given a linked list, remove the nth node from the end of list and return its head. Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the ...
3votes
1answer
211views
Reverse singly linked list
Description: Given a linked list reverse it and return the new head. Code: ...
0votes
3answers
2kviews
Move last node of the linked list to the front
Description: Given a linked list move the last node to the front. For example: 10 20 30 40 -> 40 10 20 30 Code: ...
3votes
1answer
759views
Detecting a cycle in a linked list using Java
I'm solving HackerRank "Linked Lists: Detect a Cycle" challenge. A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Complete the ...
7votes
2answers
985views
Singly Linked List "Strange sorting" exercise
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. One of these involves taking a ...
4votes
2answers
7kviews
Insert node in sorted doubly linked list
Description: Given a reference to the head of a doubly-linked list and an integer, create a new Node object having data value and insert it into a sorted linked list. Code: ...
9votes
1answer
2kviews
Get nth node from end in a linked list
Description: You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given ...
3votes
1answer
279views
Code to merge sorted linked lists in java
Since I am using Hackerrank codepair, I have to resort to inner classes. Please review the code and let me know if this can be improved. ...
5votes
2answers
5kviews
Poisonous Plants
I have solved the following problem. My code works but Hackerrank says that I can do faster: There are plants in a garden. Each of these plants has been added with some amount of pesticide. After ...
4votes
4answers
3kviews
Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
Example: If a linkedlist list contains 10->20->30->40, and 2nd node has to be deleted then the output should be 10->30->40 This question is attributed to Geeksforgeeks. Looking for code-review, ...